<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
</head>
<body>
<style>
    .lable-span {
        color: #ea2020;
    }

    .layui-form-radio > i {
        font-size: 15px;
    }
</style>
<div class="layui-form" style="padding: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名:<span class="lable-span">*</span></label>
        <div class="layui-input-block">
            <input type="text" th:value="${user.userName}" disabled lay-verify="required" autocomplete="off"
                   class="layui-input layui-disabled">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">默认密码:<span class="lable-span">*</span></label>
        <div class="layui-input-block">
            <input type="text" th:value="${user.password}" name="plainPassword" lay-verify="required|pass"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别:</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" th:field="*{user.sex}" value="男" title="男">
            <input type="radio" name="sex" th:field="*{user.sex}" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓氏:</label>
        <div class="layui-input-block">
            <input type="text" name="realName" th:value="${user.realName}" lay-verify="title" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机:<span class="lable-span">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="iphone" th:value="${user.iphone}" lay-verify="phone" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">E-mail:<span class="lable-span">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="email" th:value="${user.email}" lay-verify="email" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系地址:</label>
        <div class="layui-input-block">
            <input type="text" name="address" th:value="${user.address}" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户状态:</label>
        <div class="layui-input-block">
            <select name="status">
                <option value="1" th:selected="${user.status eq 1}">启用</option>
                <option value="0" th:selected="${user.status eq 0}">禁用</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色:</label>
        <div class="layui-input-block">
            <select name="roleId">
                <option th:each="item:${roleList}" th:text="${item.role}" th:value="${item.id}"
                        th:selected="${user.roleId eq item.id}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input name="id" hidden th:value="${user.id}">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="Submit">
                保存
            </button>
            <button type="" class="layui-btn layui-btn-primary close">
                取消
            </button>
        </div>
    </div>
</div>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            form = layui.form;
        $('.close').on('click', function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        })
        form.verify({
            pass: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格']
        });
        form.on('submit(Submit)', function (data) {
            $.ajax({
                url: '/user/user.do',
                type: 'put',
                data: data.field,
                dataType: 'json',
                async: false,
                success: function (result) {
                    if (!result.status) {
                        parent.layer.msg(result.msg, {time: 2000});
                        return false;
                    } else {
                        parent.layer.msg("编辑成功!", {time: 1000});
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layui.table.reload('tableId', {});
                    }
                }

            });
        });
    });

</script>
</body>
</html>
